Fix ICE in BuildDisposableCleanup when Dispose extension methods are in scope#19568
Draft
Fix ICE in BuildDisposableCleanup when Dispose extension methods are in scope#19568
Conversation
…in scope Use AtMostOneResult to leverage existing intrinsic-over-extension priority in AllMethInfosOfTypeInScope, matching how regular method calls resolve Dispose. Agent-Logs-Url: https://github.com/dotnet/fsharp/sessions/ebba43f1-81b6-417c-9138-f5867056fd94 Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix internal error in BuildDisposableCleanup with multiple Dispose candidates
Fix ICE in BuildDisposableCleanup when Dispose extension methods are in scope
Apr 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
BuildDisposableCleanupcrashes with an ICE ("Couldn't find Dispose on IDisposable, or it was overloaded") when a C#-styleDisposeextension method is in scope alongside the intrinsicIDisposable.Dispose.Cause
The lookup uses
TryFindIntrinsicOrExtensionMethInfowithResultCollectionSettings.AllResults, which collects both intrinsic and extension methods. The subsequent| [x] -> xmatch fails when >1 candidate is returned.Fix
Switch to
ResultCollectionSettings.AtMostOneResult. This leverages the existing priority mechanism inAllMethInfosOfTypeInScope— when intrinsic methods are found, extension methods are skipped. Same priority rules as a hand-written(x :> IDisposable).Dispose()call.